/*
*	File: main.cpp
*	Date: 12/06/2011
*	Author: Ivan Gao
*	Desc: Test the functions.
*/
#include "Vector.h"
#include <iostream>
#include "Quaternion.h"
#include "Matrix.h"
#include "BinaryFile.h"
#include "CoreBone.h"
#include "CommonDef.h"
using namespace std;
int main ()
{
	//////////////////////////////////////////////////////////////////////////
	//SVector3 test
	//////////////////////////////////////////////////////////////////////////
	SVector3 a (1.0f, 1.0f, 1.0f);
	SVector3 b (a);
	SVector3 c = a * 2;
	if (a == b)
	{
		cout<<"a == b"<<endl;
	}
	else
	{
		cout<<"a != b"<<endl;
	}
	cout<<"Length of a is "<<a.GetLength()<<endl;
	float dp1 = DotProduct(a, c);
	cout<<"Dot product of a and c is "<<dp1<<endl;
	float dp2 = a.DotProduct(b);
	if (fabs (dp1 - dp2) < 0.00001f)
	{
		cout<<"Dot product is correct."<<endl;
	}
	SVector3 cp = CrossProduct(a, c);
	a.CrossProduct(c);
	if (cp == a)
	{
		cout<<"Cross product is correct."<<endl;
	} // if


	//////////////////////////////////////////////////////////////////////////
	//SQuaternion test
	//////////////////////////////////////////////////////////////////////////
	SQuaternion q (1.0f, 1.0f, 0.0f, 1.0f);
	SQuaternion r (q);
	if (q == r)
	{
		cout<<"operator == correct."<<endl;
	}
	else
	{
		cout<<"oprator == incorrect."<<endl;
	} // if

	q.Invert();
	cout<<"x= "<<q.x<<"y = "<<q.y<<"z = "<<q.z<<"w = "<<q.w<<endl;;
// 	if (fabs (DotProduct(q, r) - 1.0f) < SIMPLEANIMATION_EPSILON)
// 	{
// 		cout<<"Invert and DotProduct correct."<<endl;
// 	}
// 	else
// 	{
// 		cout<<"Invert and DotProduct incorrect"<<endl;
// 	} // if
	q.Conjugate();
	cout<<"x= "<<q.x<<"y = "<<q.y<<"z = "<<q.z<<"w = "<<q.w<<endl;
	SQuaternion t (q);
	q *= r;
	t = CrossProduct(t, r);
	cout<<"x= "<<q.x<<"y = "<<q.y<<"z = "<<q.z<<"w = "<<q.w<<endl;
	q = t;
	cout<<"x= "<<q.x<<"y = "<<q.y<<"z = "<<q.z<<"w = "<<q.w<<endl;

	//////////////////////////////////////////////////////////////////////////
	//Matrix test
	//////////////////////////////////////////////////////////////////////////
	q.Set (0.707f, 0.0f, 0.0f, 0.707f);
	SMatrix3x3 mtx (q);
	cout<<"Matrix ="<<endl;
	for (int i = 0; i < 9; ++i)
	{
		cout<<mtx.v[i]<<' ';
		if ((i+1) %3 == 0)
		{
			cout<<endl;
		}
	} // for
	cout<<"Determinant of mtx is "<<mtx.Determinant()<<endl;
	//////////////////////////////////////////////////////////////////////////
	// SBinaryFile test.
	//////////////////////////////////////////////////////////////////////////
	ofstream file;
	file.open("a.bin", ios::out | ios::binary);
	SBinaryFile::WriteBytes(file, SimpleAnimation::SKELETON_FILE_MAGIC, sizeof(SimpleAnimation::SKELETON_FILE_MAGIC));
	//////////////////////////////////////////////////////////////////////////
	// SCoreBone test.
	//////////////////////////////////////////////////////////////////////////
	SCoreBone * pCoreBone = new SCoreBone ("aaaa");
	pCoreBone->SetParentId(-1);
	delete pCoreBone;
	return 0;
}
